<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$orderid=intval($_RQ['orderid']);
	$return['list']=array();
	$order=pdo_get('jy_kabao_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$orderid));
	$order['lognum']=pdo_count('jy_kabao_songlog',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$orderid));
	$order['lognum2']=pdo_count('jy_kabao_songlog',array('status'=>2,'uniacid'=>$_SESSION['uniacid'],'orderid'=>$orderid));
	$order['lslognum']=$order['total']-$order['lognum']+$order['lognum2'];
	$return['order']=$order;
	$return['params']['status']=intval($_RQ['status']);
	$return['params']['orderid']=$orderid;
	exi($return);
}
if($_RQ['op']=='list'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'fmid'=>$_SESSION['uid'],'isdel'=>0);
	if($_RQ['status']){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=intval($_RQ['status']);
	}
	if($_RQ['orderid']){
		$params['orderid']=intval($_RQ['orderid']);
		$return['params']['orderid']=intval($_RQ['orderid']);
	}
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=intval($_RQ['mid']);
	}
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:10;
	$list=pdo_getslice('jy_kabao_songlog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['fmember']=cfc('core')->member_show($item['fmid']);
			$order=pdo_get('jy_kabao_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['orderid']));
			if($order['listid']){
				$item['kabao']=pdo_get('jy_kabao_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['listid']),array('id','image','title','desc','price'));
			}else{
				$item['kabao']=json_decode($order['diyinfo'],true);
			}
			$item['gettime']=$item['gettime']?date('Y-m-d H:i:s',$item['gettime']):'';
			$item['uptime']=$item['uptime']?date('Y-m-d H:i:s',$item['uptime']):'';
			$item['endtime']=$item['endtime']?date('Y-m-d H:i:s',$item['endtime']):'';
			$item['statustitle']=$this->songlog_status[$item['status']];
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='del'){
	$post=get_postdata();	
	$id=intval($post['id']);
	if($id){
		$songlog=pdo_get('jy_kabao_songlog',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		if($songlog['status']==1){
			exi('已领取的不能删除！！','error');
		}
		pdo_delete('jy_kabao_songlog',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		exi('删除成功！','','/songlog/');		
	}else{		
		exi('删除失败！','error');
	}

}